﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 龙润数据采集.DAL
{
    class LongRunDAL
    {
        private ConnectionConfig connection = null;
        public SqlSugarClient db = null;
        public LongRunDAL()
        {
            string SqlIP = "192.168.2.2";
            string database = "ECU";
            string uid = "sa";
            string pwd = "8ik,9ol.";
            connection = new ConnectionConfig()
            {
                ConnectionString = "server='" + SqlIP + "';initial catalog='" + database + "';uid='" + uid + "';pwd='" + pwd + "'",
                DbType = DbType.SqlServer,
                IsAutoCloseConnection = true,
                InitKeyType = InitKeyType.Attribute
            };
            db = new SqlSugarClient(connection);
        }
        public bool Query(Model.EcuDb.ECT_Test ect)
        {
            try
            {
                int count = -1;
                if (ect.writeCode==null)
                {
                    count = db.Queryable<Model.EcuDb.ECT_Test>()
                    .Count(it => it.testTime == ect.testTime
                    && it.testCode == ect.testCode );
                }
                else
                {
                    count = db.Queryable<Model.EcuDb.ECT_Test>()
                   .Count(it => it.testTime == ect.testTime
                   &&  it.writeCode == ect.writeCode);
                }
                return count == 0;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public bool Insert(Model.EcuDb.ECT_Test ect)
        {
            try
            {
                int count = db.Insertable(ect).ExecuteCommand();
                return count == 1;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
